package com.elai.analytics.controller;
import com.alibaba.fastjson.JSONObject;
import com.elai.analytics.domain.ColumnHeader;
import com.elai.common.core.controller.BaseController;
import com.elai.common.core.domain.AjaxResult;
import com.elai.common.utils.ThirdProperties;
import org.apache.commons.collections4.map.HashedMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 只能推荐Controller
 *
 * @author elai
 * @date 2021-06-19
 */
@RestController
@RequestMapping("/report/path")
public class PathAnalyticsController extends BaseController
{
    private static final Logger log = LoggerFactory.getLogger(PathAnalyticsController.class);

    @Autowired
    private ThirdProperties thirdProperties;




    @PostMapping("/pathAnalyQuery")
    public AjaxResult pathAnalyQuery(@RequestBody String requestJson)
    {
        /*
        chartData:{"nodes": [
            {"name": "起始事件"},
            {"name": "$启动App"},
            {"name": "App元素点击"},
            {"name": "App激活"},
            {"name": "结束事件"}
        ],
            "links": [
            {"source": "起始事件", "target": "App激活", "value": 82},
            {"source": "起始事件", "target": "$启动App", "value":704},
            {"source": "起始事件", "target": "App元素点击", "value": 97},
            {"source": "$启动App", "target": "App元素点击", "value": 97},
            {"source": "App元素点击", "target": "App激活", "value": 17},
            {"source": "App激活", "target": "结束事件", "value": 317}
        ]}
        */



        log.info("keepAnalyQuery："+requestJson);
        JSONObject paramJson = JSONObject.parseObject(requestJson);
        JSONObject keepJson = paramJson.getJSONObject("requestJson");

        Map<String, Object> paramMap =new HashedMap();
        Map<String,Object> resultMap=new HashMap();

        List<Map> nodesList=new ArrayList<>();
        Map node1=new HashMap();
        node1.put("name","起始事件");
        nodesList.add(node1);

        Map node2=new HashMap();
        node2.put("name","$启动App");
        nodesList.add(node2);

        Map node3=new HashMap();
        node3.put("name","App元素点击");
        nodesList.add(node3);

        Map node4=new HashMap();
        node4.put("name","App激活");
        nodesList.add(node4);

        Map node5=new HashMap();
        node5.put("name","结束事件");
        nodesList.add(node5);

        List<Map> linksList=new ArrayList<>();
        Map link1=new HashMap();
        link1.put("source","起始事件");
        link1.put("target","App激活");
        link1.put("value",82);
        linksList.add(link1);

        Map link2=new HashMap();
        link2.put("source","起始事件");
        link2.put("target","$启动App");
        link2.put("value",704);
        linksList.add(link2);

        Map link3=new HashMap();
        link3.put("source","起始事件");
        link3.put("target","App元素点击");
        link3.put("value",97);
        linksList.add(link3);

        Map link4=new HashMap();
        link4.put("source","$启动App");
        link4.put("target","App元素点击");
        link4.put("value",97);
        linksList.add(link4);

        Map link5=new HashMap();
        link5.put("source","App元素点击");
        link5.put("target","App激活");
        link5.put("value",17);
        linksList.add(link5);

        Map link6=new HashMap();
        link6.put("source","App激活");
        link6.put("target","结束事件");
        link6.put("value",317);
        linksList.add(link6);

        resultMap.put("nodes",nodesList);
        resultMap.put("links",linksList);

        return AjaxResult.success(resultMap);
    }

}
